<template>
  <div>
      <el-row>
          <el-col :span="24" align="right">
              <div style="margin-top:10px">
                <el-button @click="addNewRecord" type="primary">添加机构</el-button>
                <el-input style="width:200px" v-model="filters.orgName" placeholder="请输入机构名称"></el-input>
                <el-select v-model="filters.orgType" placeholder="请选择机构类型">
                  <el-option v-for="(v,i) of OrgType" :key="i" :value="v.orgTypeValue" :label="v.orgTypeName"></el-option>
                </el-select>
                <el-select v-model="filters.levelType" placeholder="请选择机构级别">
                  <el-option v-for="(v,i) of LevelType" :key="i" :value="v.levelTypeValue" :label="v.levelTypeName"></el-option>
                </el-select>
                <el-button type="primary" icon="search" @click="getOrgInfo">搜索</el-button>
                <el-button type="primary" @click="flushAll">刷新</el-button>
              </div>
              <el-row style="margin-top:20px">
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?3:0">
                      <treeComponent style="margin-top:-52px" @GetNodeValue="GetNodeValue"></treeComponent>
                  </el-col>
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?21:24">
                      <el-table :data="list" border>
                          <el-table-column  v-for="(v,k,i) in props" :key="i" :label="labels[i]" align="center">
                              <template scope="scope">
                                  <span v-if="k==='sex'">
                                       {{scope.row[k]==1?'男':'女'}}
                                  </span>
                                  <span v-else>
                                      {{scope.row[k]}}
                                  </span>
                              </template>
                          </el-table-column>
                          <el-table-column label="操作" width="200" align="center">
                              <template scope="scope">
                                  <el-button type="text" @click="ckDetail(scope.row.orgID)">查看详情</el-button>
                                  <el-button type="text" @click="editOrgInfo(scope.row.orgID)">编辑</el-button>
                                  <el-button type="text" @click="deleteOrgInfo(scope.row.orgID)">删除</el-button>
                              </template>
                          </el-table-column>
                      </el-table>
                      <el-pagination style="margin-top:10px" layout="prev, pager, next" :total="totalInfo" :current-page="currentPage" @current-change="handleCurrentChange">
                      </el-pagination>
                  </el-col>
              </el-row>
          </el-col>
      </el-row>

    <el-dialog top="5%" title="查看详情" :visible.sync="visible">
      <info :id="id"></info>
    </el-dialog>
  </div>
</template>

<script>
import treeComponent from "../../components/common/treeComponent";
import * as api from "@/api/videoManage";
import * as api2 from "@/api/zonghezhili/duiwujianshe";
import info from "./orgInfo"
import treeComponentVue from '../../components/common/treeComponent.vue';
export default {
  components: {
    treeComponent: treeComponent,
    info:info
  },
  data() {
    return {
      filters: {
        orgName: null, //机构名称
        orgType: null, //机构类别
        netGridID: null, // 所属网格
        levelType: null,
        page: 1,
        pageSize: 10
      },
      currentPage:1,
      OrgType: [],
      LevelType: [],
      list: [
        {
          orgID: "", //                bigint not null auto_increment,
          orgName: "", //              varchar(100) not null comment '机构名称',
          orgTypeValue: "", //         varchar(2),
          levelTypeValue: "", //       varchar(2),
          netGridID: "", //            bigint,
          orgCreateDate: "", //        date,
          orgContactName: "", //       varchar(50) comment '机构联系人姓名',
          orgContactTel: "", //        varchar(20) comment '机构联系电话',
          orgBriefIntroduction: "", // varchar(200),
          businessGuidanceDepartment: "", // varchar(200) comment '业务指导部门',
          personNumber: "", //         int comment '人员数量',
          mainFunction: "" //         varchar(1024) comment '主要职能',
        }
      ],
      totalInfo: 0,
      props: {
        orgName: "", //              varchar(100) not null comment '机构名称',
        orgTypeName: "",
        levelTypeName: "",
        orgContactName: "", //       varchar(50) comment '机构联系人姓名',
        orgContactTel: "", //        varchar(20) comment '机构联系电话',
        personNumber: "", //         int comment '人员数量',
        netGridName: ""
      },
      labels: [
        "机构名称",
        "机构类型",
        "机构级别",
        "机构联系人",
        "机构联系热方式",
        "机构人数",
        "所属网格"
      ],
      id:"1",
      visible:false
    };
  },
  methods: {
    deleteOrgInfo(id) {
      this.$confirm("是否删除此驾驶员记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          api2.deleteOrgBasicInfo(id).then(res => {
            if (res.data) {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.getOrgInfo();
            } else {
              this.$message({
                type: "error",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    flushAll() {
      this.filters.orgName = this.filters.orgType = this.filters.levelType = null;
      if (this.$store.getters.user.userRole == "超级管理员") {
        this.filters.netGridID = null;
      }
      this.getOrgInfo();
    },
    handleCurrentChange(val) {
      this.filters.page = val;
      this.getOrgInfo();
    },
    ckDetail(id) {
      this.id = id;
      this.visible = true;
    },
    addNewRecord() {
      this.$router.push("add");
    },
    GetNodeValue(val) {
      this.filters.netGridID = val;
      this.getOrgInfo();
    },
    editOrgInfo(id) {
      this.$router.push({ path: "edit", query: { id: id } });
    },
    getOrgInfo() {
      api2.getOrgBasicInf(this.filters).then(res => {
        this.list = res.data.vos;
        this.totalInfo = res.data.page.totalCount;
      });
      this.filters.orgName = this.filters.orgType = this.filters.levelType = null;
    }
  },
  mounted() {
    this.$store.commit("INIT_PAGE","A");
    this.filters.page = this.$store.getters.page['A']
    this.currentPage = this.filters.page;

    if (this.$store.getters.user.userRole != "超级管理员")
      this.filters.netGridID = this.$store.getters.user.netGridID;
    this.getOrgInfo();
    api2.fetchALLTYPEInfo().then(res => {
      this.OrgType = res.organizationTypes;
      this.LevelType = res.levelTypes;
    });
  }
};
</script>


<style scoped>

</style>
